package com.gimi.cloud.bbp.app.consumer.service.mall.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gimi.cloud.bbp.app.consumer.feign.mall.MallSuggestFeignService;
import com.gimi.cloud.bbp.app.consumer.service.mall.MallSuggestService;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.mall.MallSuggestDTO;

/**
 * 用户建议服务
 * @author lilinfeng
 */
@Service
public class MallSuggestServiceImpl implements MallSuggestService {
	private static final Logger log = LoggerFactory.getLogger(MallSuggestServiceImpl.class);
	@Autowired private MallSuggestFeignService mallSuggestFeignService;

	@Override
	public void submitMallSuggest(String requestData, HttpServletRequest request, HttpServletResponse response) {
		log.info("请求参数===>" + JsonUtil.replaceNow(requestData));
		MallSuggestDTO dto = JsonUtil.jsonToBean(requestData,MallSuggestDTO.class);
		if (StringUtils.isBlank(dto.getSuMobilePhone())) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"联系电话不能为空");
		}
		if (StringUtils.isBlank(dto.getSuSuggest())) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"意见反馈不能为空");
		}
		dto.setUserId(Integer.valueOf(request.getHeader("userId")));
        Util.sendResponse(mallSuggestFeignService.submitMallSuggest(dto), response);
	}

}
